import { ref, watch, reactive } from "vue"
import request from '@/utils/request'
import {Plus, Search} from '@element-plus/icons-vue'

// 缴费
export const paymentApi = (dataRequest) => {
    return request({
        url: '/student/batch/pay/batch',
        method: 'POST',
        data: dataRequest
    })
}

// 批次下学员缴费总额和缴费金额
export const getPayAndTotalPrice = (batchId) => {
    return request({
        url: '/student/batch/count/student/price/' + batchId,
        method: 'GET',
    })
}

// 设置题库类型
export const bankSetApi = (dataRequest) => {
    return request({
        url: '/student/batch/bank/type',
        method: 'POST',
        data: dataRequest
    })
}

// 校验科目类别是否统一
export const verifyCourseIdApi = (dataRequest) => {
    return request({
        url: '/student/batch/verify/course',
        method: 'POST',
        data: dataRequest
    })
}

// 设置过期时间
export const setExpireDateApi = (dataRequest) => {
    return request({
        url: '/student/batch/set/lineDate',
        method: 'POST',
        data: dataRequest
    })
}

// 审核通过
export const checkStudentApi = (dataRequest) => {
    return request({
        url: '/student/batch/check/student',
        method: 'POST',
        data: dataRequest
    })
}

// 设置学员单价
export const setUnitPayPrice = (dataRequest) => {
    return request({
        url: '/student/batch/set/unit/price',
        method: 'POST',
        data: dataRequest
    })
}

// 批量删除
export const batchDelApi = (dataRequest) => {
    return request({
        url: '/student/batch/del',
        method: 'DELETE',
        data: dataRequest,
    })
}

// 微信解绑
export const batchCancelBindApi = (dataRequest) => {
    return request({
        url: '/student/batch/cancel/bind',
        method: 'POST',
        data: dataRequest,
    })
}

// 分页
export function studentListApi(dataRequest) {
    return request({
        url: '/student/batch/view/student',
        method: 'POST',
        data: dataRequest
    })
}

// 修改学员科目
export function studentCourseEditApi(dataRequest) {
    return request({
        url: '/student/course',
        method: 'PUT',
        data: dataRequest
    })
}

// 启用/禁用学员
export function studentStatusChangeApi(dataRequest) {
    return request({
        url: '/student/course/status',
        method: 'PUT',
        data: dataRequest
    })
}
export const examineObj = reactive({})
export const tableItem = reactive({
    tree: false,//树形
    loading: false,
    expandAll: true,//树形默认展开
    select: true,//多选框
    align: 'center',//对齐方式 全局
    signalToSelection: true,//重新请求分页的时候，给table发信号，使原本选中的行保持选中
    column: [
        {
            label: '姓名',
            prop: 'name',
        },
        {
            label: '身份证号',
            prop: 'idCard',
        },
        {
            label: '手机号',
            prop: 'phone',
        },
        {
            label: '科目',
            prop: 'courseName',
        },

        {
            label: '账号期限',
            prop: 'accountPeriod',
            width: 170
        },
        {
            label: '题库类型',
            prop: 'courseBankTypeName'
        },
        {
            label: '学员单价',
            prop: 'unitPayPrice'
        },
        {
            label: '审核结果',
            prop: 'statusText',
        },
        {
            label: '备注',
            prop: 'remark',
            tooltip: true
        },
        {
            label: "操作",
            prop: "action"
        }
    ],
    pageInfo: {
        request: {
            'id': '',
            'name': '',
            'idCard': '',
            'studentAuditStatus': '',//1未审核 2已通过 3已过期 4禁用
            'pageDomain': {
                'pageNum': null,//分页页面数 必须为数字
                'pageSize': 10000,//分页页面数据大小  必须为数字
                'orderByColumn': null,//搜索参数
                'isAsc': null,//搜索参数
                'reasonable': '',//搜索参数
                'date': ''

            }
        },
        pagesClose: true,//是否关闭分页显
        closeMountedPaging: true,//是否关闭分页显示
        // 分页函数paging
        paging:  function () {
            tableItem.loading = true
            tableItem.tableData.data=[]
            tableItem.tableData.total=0
            tableItem.tableData.data.payPrice=0
             studentListApi(tableItem.pageInfo.request).then(res => {
                tableItem.tableData.data = res.rows
                tableItem.tableData.total = res.total
                if (!tableItem.tableData.data && tableItem.tableData.data.length == 0) { return }
                let index = 0;
                tableItem.tableData.data.map((item) => {
                    item.index = index++; //添加index，可以标识选中的行是第几行
                    item.status == 1 ? item.statusText = '未审核' : ''
                    item.status == 2 ? item.statusText = (item.closeButton = "删除", '已通过') : ''
                    item.status == 3 ? item.statusText = '已过期' : ''
                    item.status == 4 ? item.statusText = '禁用' : ''
                    if (item.startDate && item.lineDate) {
                        item.accountPeriod = item.startDate + "至" + item.lineDate
                    } else {
                        item.accountPeriod = ''
                    }
                })
                tableItem.loading = false
            }).catch(() => { tableItem.loading = false });
            getPayAndTotalPrice(tableItem.pageInfo.request.id).then(res => {
                examineObj.payPrice = res.data.payPrice || 0
                examineObj.studentTotalPrice = res.data.studentTotalPrice || 0
              }).catch(() => { })
        }
    },
    // 分页数据 自定义分页函数paging时需要把值赋给tableData
    tableData: {
        total: '',//分页总计
        // 分页数据
        data: []
    },
    moreBtnArray: [],
    // 操作栏按钮
    btnArray: [],
    // 选择框触发
    selectChange: function (row) {
        console.log(row)
    },
})
export const operationItem = reactive({
    defaultSearch: false,//默认搜索按钮
    SearchText: '',
    defaultRefresh: false,//默认重置按钮
    customTableHeader: false,//
    SearchItem: [
        {
            code: "name",
            name: "姓名",
            type: "input",
        },
        {
            code: "idCard",
            name: "身份证号",
            type: "input",
        },
        {
            code: "studentAuditStatus",
            name: "状态",
            type: "select",
            options: [
                {
                    value: '1',
                    label: '未审核'
                },
                {
                    value: '2',
                    label: '已通过'
                },
                {
                    value: '3',
                    label: '已过期'
                },
                {
                    value: '4',
                    label: '禁用'
                }
            ]
        },

    ],
    menuArray: [
        {
            show: true,
            type: 'primary',
            text: '查询',
            icon: Search,
            handle: () => {
            }
        }
    ]
})


